package com.zsl.casuallyheart.util;

import com.zsl.casuallyheart.R;

import android.content.Context;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 设置title
 * @author zsl
 * @date 2014-10-13下午9:59:12
 * @version v1.0
 */
public class SetTitle {
	private static SetTitle setTitle;
	private static Context context;
	private static LayoutInflater inflater;
	
	public static SetTitle getInstace(Context context1){
		context=context1;
		inflater=LayoutInflater.from(context);
		if (setTitle!=null) {
			return setTitle;
		} 
		return new SetTitle();
	}
	/**
	 * 添加titile
	 * @param contents 左、中、右的显示的字符
	 * @param onClickListeners 左、中、右的点击事件 
	 */
	public void setTitleContent(int layout,String[] contents,OnClickListener[] onClickListeners){
		if (contents.length!=3) {
			Toast.makeText(context, "传的参数contents因为三个字符串例如【new String[]{\"左\",\"标题\",\"右\"}】", Toast.LENGTH_LONG).show();
			return;
		}
		if (onClickListeners.length!=3) {
			Toast.makeText(context, "传的参数onClickListeners因为三个点击事件例如【new OnClickListener[]{oc1,oc1,oc1】", Toast.LENGTH_LONG).show();
			return;
		}
		View view=inflater.inflate(layout, null);
		TextView tv_left=(TextView) view.findViewById(R.id.layout_title_tv_left);
		TextView tv_title=(TextView) view.findViewById(R.id.layout_title_tv_title);
		TextView tv_right=(TextView) view.findViewById(R.id.layout_title_tv_right);
		tv_left.setText(contents[0]);
		tv_title.setText(contents[1]);
		tv_right.setText(contents[2]);
		
		tv_left.setOnClickListener(onClickListeners[0]);
		tv_title.setOnClickListener(onClickListeners[1]);
		tv_right.setOnClickListener(onClickListeners[2]);
		
	}
}
